﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CuTextSelectBox : System.Web.UI.UserControl
{
    private int openPageWidth = 466;
    private int openPageHeight = 362;
    private int textValueValidateID = -1;
    private bool isValidateDateTime = false;
    private string validateText;
    private string returnTextIDs;
    private string openPageUrl;
    private string openBtnOutUrl = "../App_Images/ico/19.gif";
    private string openBtnOverUrl = "../App_Images/ico/20.gif";
    private int iflag = -1;

    public int Flag
    {
        get { return iflag; }
        set { iflag = value; }
    }

    public bool IsValidateDateTime
    {
        get { return isValidateDateTime; }
        set { isValidateDateTime = value; }
    }
    public bool ReadOnly
    {
        get { return this.txtBox.ReadOnly; }
        set { this.txtBox.ReadOnly = value; }
    }
    public Unit Width
    {
        get { return this.txtBox.Width; }
        set { this.txtBox.Width = new Unit(value.Value - 18); }
    }
    public Unit Height
    {
        get { return this.txtBox.Height; }
        set { this.txtBox.Height = value; }
    }
    public Unit OpenBtnWidth
    {
        get { return this.imgOpen.Width; }
        set { this.imgOpen.Width = value; }
    }
    public Unit OpenBtnHeight
    {
        get { return this.imgOpen.Height; }
        set { this.imgOpen.Height = value; }
    }
    public int OpenPageWidth
    {
        get { return openPageWidth; }
        set { openPageWidth = value; }
    }
    public int OpenPageHeight
    {
        get { return openPageHeight; }
        set { openPageHeight = value; }
    }
    public int TextValueValidateID
    {
        get { return textValueValidateID; }
        set { textValueValidateID = value; }
    }
    public string ValidateText
    {
        get { return validateText; }
        set { validateText = value; }
    }
    public string ReturnTextIDs
    {
        get { return returnTextIDs; }
        set { returnTextIDs = value; }
    }
    public string CssClass
    {
        get { return this.txtBox.CssClass; }
        set { this.txtBox.CssClass = value; }
    }
    public string Text
    {
        get { return this.txtBox.Text; }
        set { this.txtBox.Text = value; }
    }
    public string ToolTip
    {
        get { return this.txtBox.ToolTip; }
        set { this.txtBox.ToolTip = value; }
    }
    public string OpenPageUrl
    {
        get { return openPageUrl; }
        set { openPageUrl = value; }
    }
    public string OpenBtnOutUrl
    {
        get { return openBtnOutUrl; }
        set { openBtnOutUrl = value; }
    }
    public string OpenBtnOverUrl
    {
        get { return openBtnOverUrl; }
        set { openBtnOverUrl = value; }
    }


    protected void Page_Load(object sender, EventArgs e)
    { }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (this.txtBox.ReadOnly)
        {
            this.panel.BorderWidth = 0;
            this.imgOpen.Visible = false;
            this.txtBox.Attributes.Add("OnMouseOver", "this.style.cursor='default'");
        }
        else
        {
            this.panel.BorderWidth = 1;
            this.imgOpen.Visible = true;
            this.txtBox.Attributes.Add("OnMouseOver", "this.style.cursor='text'");
        }

        this.imgOpen.Attributes.Add("OnMouseOut", "this.src='" + this.openBtnOutUrl + "'");
        this.imgOpen.Attributes.Add("OnMouseOver", "this.src='" + this.OpenBtnOverUrl + "'");
        this.imgOpen.Attributes.Add("OnClick", "openModalDialog('" + this.OpenPageUrl + "'," + this.openPageWidth + "," + this.openPageHeight + ",'" + this.txtBox.ClientID + "','" + this.returnTextIDs + "',"+ this.iflag +")");

        if (this.textValueValidateID != -1)
        {
            if (this.textValueValidateID == 0)
            {
                this.txtBox.Attributes.Add("OnChange", "ValidateDateTime(document.getElementById('" + this.txtBox.ClientID + "').value)");
            }
            //else if (this.textValueValidateID == 1)//不能为空
            //{
            //    this.txtBox.Attributes.Add("onblur", "if(value.Trim() == ''){alert('当前项不能为空');this.select();this.focus();return false;}");
            //}
            else
            {
                this.txtBox.Attributes.Add("OnChange", "sender(" + textValueValidateID + ",'" + this.txtBox.ClientID + "','" + this.returnTextIDs + "','" + this.openPageUrl + "'," + this.openPageWidth + "," + this.openPageHeight + ")");
            }
        }
    }
}
